package com.yl.ydk.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.yl.ydk.R
import com.yl.ydk.base.BaseFragment
import com.yl.ydk.bean.DiseaseCateBean
import com.yl.ydk.ui.activity.DiseaseCateActivity
import com.yl.ydk.ui.activity.DiseaseDetailActivity
import com.yl.ydk.ui.adapter.DiseaseDetailAdapter
import kotlinx.android.synthetic.main.fragment_dissease_detail.*

class DiseaseDetailFragment : BaseFragment() {

    private var adapter: DiseaseDetailAdapter? = null

    private var symptom: MutableList<DiseaseCateBean.Symptom>? = null

    companion object {
        fun getInstance(symptom: MutableList<DiseaseCateBean.Symptom>): DiseaseDetailFragment {
            val sf = DiseaseDetailFragment()
            sf.symptom = symptom
            return sf
        }
    }

    override fun getLayoutResId(): Int = R.layout.fragment_dissease_detail

    override fun attachView() {

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        adapter = DiseaseDetailAdapter(symptom)
        rvDiseaseDetail.adapter = adapter
        val manager = LinearLayoutManager(activity)
        manager.orientation = LinearLayoutManager.VERTICAL
        rvDiseaseDetail.layoutManager = manager

        adapter?.onListItemClick(object : DiseaseDetailAdapter.onListItemClick {
            override fun onListItemClick(item: DiseaseCateBean.Symptom?) {
                DiseaseCateActivity.diseaseCateActivity?.let {
                    val intent = Intent(it, DiseaseDetailActivity::class.java)
                    intent.putExtra("data",item?.name)
                    it.startActivityIn(intent, it)
                }
            }
        })

    }

}